package tree;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;

//项目树的节点对象
public class ProjectTreeNode extends DefaultMutableTreeNode {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//该节点对应的文件
	private File file;
	
	//该节点的子节点
	private List<ProjectTreeNode> children;
	
	public ProjectTreeNode(File file, boolean allowChildren){
		super(file.getName(),allowChildren);
		this.setFile(file);
		//初始化子节点
		children = new ArrayList<ProjectTreeNode>();
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public List<ProjectTreeNode> getChildren() {
		//清空children，再重新获取一次
		children.removeAll(children);
		for(int i = 0;i<getChildCount();i++){
			children.add((ProjectTreeNode)getChildAt(i));
		}
		return children;
	}	
}
